'use strict';

const {Controller} = require('egg');

class HomeController extends Controller {
    async index() {
        const {ctx} = this;
        const arrs = []
        try {
            // 遍历处理多个文件
            for (const file of ctx.request.files) {
                const filePath = await ctx.helper.uploadLocaFile({file})
                console.log(filePath)
                arrs.push(filePath)
            }
            ctx.body = 1
        } catch (e){
            console.log(e)
        } finally {
            // 需要删除临时文件
            await ctx.cleanupRequestFiles();
        }
    }

    async uploadImg() {
        const {ctx} = this;
        try {
            // 遍历处理多个文件
            for (const file of ctx.request.files) {
                const filePath = await ctx.helper.uploadLocalImage({file})
            }
        } finally {
            await ctx.cleanupRequestFiles();   // 需要删除临时文件
        }
    }
}

module.exports = HomeController;
